local _, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local PlayerIsML = ZL.PlayerIsML
local pruneCrossRealm = ZL.pruneCrossRealm
local FetchDataFromItemId = ZL.FetchDataFromItemId
local Prefix = ZL.Prefix
local TransmitAddonInfo_Pro = ZL.TransmitAddonInfo_Pro
local tableSort = ZL.tableSort

-- 依赖库: AceAddon-3.0, AceComm-3.0, LibSerialize, LibDeflate
MyAddon = LibStub("AceAddon-3.0"):NewAddon("AutoAuction", "AceComm-3.0")
local LibSerialize = LibStub("LibSerialize")
local LibDeflate = LibStub("LibDeflate")
-- 插件启用时的函数
function MyAddon:OnEnable()
    self:RegisterComm("AUTOAUC SYNC") --data.type={"开始拍卖", "取消拍卖", "", "", "", "", "", "", ""}
    self:RegisterComm("AUTOAUC RESET") --初始化全员拍卖插件
    self:RegisterComm("AUTOAUC PRO") --同步全局配置参数
    self:RegisterComm("AUTOAUC REVOKE") --删除指定玩家的出价
    self:RegisterComm("AUTOAUC VER") --请求检测全团是否有安装插件及插件的版本并且处理反馈回的消息(data.type=request, requestback)
end

function MyAddon:TransmitAddonInfo(prefix, data)
    if PlayerIsML() and data then
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- self:SendCommMessage(prefix, encoded, "WHISPER", "潇湘凌风")
        self:SendCommMessage(prefix, encoded, "RAID")
    end
end

function MyAddon:TransmitAddonInfo2(prefix, data, chatType, targetName)
    if data then
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        if chatType == "WHISPER" then
            self:SendCommMessage(prefix, encoded, "WHISPER", targetName)
        else
            self:SendCommMessage(prefix, encoded, chatType)
        end
    end
end

function MyAddon:OnCommReceived(prefix, payload, distribution, sender)
    local AuctionFrame = ZL.AuctionFrame
    sender = pruneCrossRealm(sender)
    -- print(Prefix("收到%s发送的信息"):format(sender))
    local decoded = LibDeflate:DecodeForWoWAddonChannel(payload)
    if (not decoded) then
        -- print("解码失败！")
        return
    end
    local decompressed = LibDeflate:DecompressDeflate(decoded)
    if (not decompressed) then
        -- print("解压失败！")
        return
    end
    local success, fdata = LibSerialize:Deserialize(decompressed)
    if (not success) then
        -- print("转换失败！")
        return
    end
    if (prefix == "AUTOAUC SYNC") then
        if (PlayerIsML(sender)) then
            if fdata.type == "开始拍卖" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if (not data) then
                    data = {
                        ["itemId"] = fdata.itemId,
                        ["itemlink"] = fdata.itemlink,
                        ["itemindex"] = fdata.itemindex,
                        ["startbidamount"] = fdata.startbidamount,
                        ["bidIncrement"] = fdata.bidIncrement,
                        ["state"] = "auctioning",
                        ["lgnore"] = false,
                        ["countdownremaining"] = fdata.auctionTimer,
                        ["isPaused"] = false,
                        ["bidderlist"] = {},
                        ["itemCount"] = fdata.itemCount,
                    }
                    if (not ZL_CURRENT.auctionlist) then --如果当前不存在拍卖记录，则创建
                        local name, _, difficultyID, _, _, _, _, instanceID = GetInstanceInfo()
                        ZL_CURRENT.auctionlist = {}
                        ZL_CURRENT.name = name
                        ZL_CURRENT.difficultyID = difficultyID
                        ZL_CURRENT.instanceID = instanceID
                        ZL_CURRENT.auctiondate =  date("%Y-%m-%d %H:%M:%S", time())
                        ZL_CURRENT.totalincome = 0
                        ZL_CURRENT.IncomeList = {}
                    end
                    table.insert(ZL_CURRENT.auctionlist, data)
                    index = #ZL_CURRENT.auctionlist
                else
                    ZL_CURRENT.auctionlist[index].startbidamount = fdata.startbidamount
                    ZL_CURRENT.auctionlist[index].bidIncrement = fdata.bidIncrement
                    ZL_CURRENT.auctionlist[index].state = "auctioning"
                    ZL_CURRENT.auctionlist[index].countdownremaining = fdata.auctionTimer
                    ZL_CURRENT.auctionlist[index].isPaused = false
                    ZL_CURRENT.auctionlist[index].bidderlist = {}
                    ZL_CURRENT.auctionlist[index].itemCount = fdata.itemCount
                end
                local f =  AuctionFrame.entries[index]
                f:SetValues(index)
                AuctionFrame:Update()
            elseif fdata.type == "取消拍卖" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    local f = AuctionFrame.entries[index]
                    f.Frame1.timer.updateframe:Hide()
                    f.Frame1.statetext:SetText("拍卖已取消，等待重新拍卖")
                    f.Frame1.curbidamounttext:SetText("有效出价：")
                    f.Frame1.curbiddertext:SetText("当前无人出价！")
                    if f.Frame1.timer:IsPaused() then
                        f.Frame1.timer:Resume()
                        f.Frame1.MLframe.PauseBtn:SetText("暂停")
                    end
                    f.Frame1.timer:SetCooldown(0, 0)
                    f.Frame1.timer.cooldownText:SetText("")
                    f.Frame1.bidbox:Disable()
                    f.Frame1.bidBtn:Disable()
                    f.Frame1.autobidBtn:Disable()
                    f.Frame1.MLframe.PauseBtn:Disable()
                    f.Frame1.MLframe.CountDownBtn:Disable()
                    f.Frame1.MLframe.reverseBidBtn:Disable()
                    ZL_CURRENT.auctionlist[index].state = "waiting"
                    ZL_CURRENT.auctionlist[index].countdownremaining = 0
                    ZL_CURRENT.auctionlist[index].isPaused = false
                    ZL_CURRENT.auctionlist[index].bidderlist = {}
                    AuctionFrame:Update()
                end
            elseif fdata.type == "同步所有" then
                if (not PlayerIsML()) then
                    if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                        for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                            local f = AuctionFrame.entries[num]
                            if data.state == "auctioning" then
                                f.Frame1.timer.updateframe:Hide()
                                f.Frame1.statetext:SetText("拍卖已取消，等待重新拍卖")
                                f.Frame1.curbidamounttext:SetText("有效出价：")
                                f.Frame1.curbiddertext:SetText("当前无人出价！")
                                if f.Frame1.timer:IsPaused() then
                                    f.Frame1.timer:Resume()
                                    f.Frame1.MLframe.PauseBtn:SetText("暂停")
                                end
                                f.Frame1.timer:SetCooldown(0, 0)
                                f.Frame1.bidbox:Disable()
                                f.Frame1.bidBtn:Disable()
                                f.Frame1.autobidBtn:Disable()
                                f.Frame1.MLframe.PauseBtn:Disable()
                                f.Frame1.MLframe.CountDownBtn:Disable()
                                f.Frame1.MLframe.reverseBidBtn:Disable()
                            end
                            f:Hide()
                        end
                    end
                    ZL_CURRENT = fdata.current
                    if ZL_CURRENT.auctionlist and (#ZL_CURRENT.auctionlist > 0) then
                        for num, _ in ipairs(ZL_CURRENT.auctionlist) do
                            local f = AuctionFrame.entries[num]
                            f:SetValues(num)
                        end
                    end
                    AuctionFrame:Update()
                end
                if ZL_CURRENT["auctionlist"] and #ZL_CURRENT["auctionlist"] > 0 then
                    for index, data in ipairs(ZL_CURRENT["auctionlist"]) do
                        if data.state == "auctioning" and data.isPaused and data.isPausedLinshi then
                            data["isPaused"] = false
                            data.isPausedLinshi = false
                            local f = AuctionFrame.entries[index]
                            f.Frame1.timer:Resume()
                            f.Frame1.statetext:SetText("拍卖中...")
                            if f.maxAutoBid then
                                f.Frame1.bidbox:Disable()
                                f.Frame1.bidBtn:Disable()
                                f.Frame1.lgnoreBtn:Disable()
                            else
                                f.Frame1.bidbox:Enable()
                                f.Frame1.bidBtn:Enable()
                                f.Frame1.lgnoreBtn:Enable()
                            end
                            f.Frame1.autobidBtn:Enable()
                        end
                    end
                end
            elseif fdata.type == "同步单个" then
                local itemId = fdata.curAuction.itemId
                local itemindex = fdata.curAuction.itemindex
                local data, index = FetchDataFromItemId(itemId, itemindex)
                if (not data) then
                    if (not ZL_CURRENT.auctionlist) then --如果当前不存在拍卖记录，则创建
                        local name, _, difficultyID, _, _, _, _, instanceID = GetInstanceInfo()
                        ZL_CURRENT.auctionlist = {}
                        ZL_CURRENT.name = name
                        ZL_CURRENT.difficultyID = difficultyID
                        ZL_CURRENT.instanceID = instanceID
                        ZL_CURRENT.auctiondate =  date("%Y-%m-%d %H:%M:%S", time())
                        ZL_CURRENT.totalincome = 0
                        ZL_CURRENT.IncomeList = {}
                    end
                    table.insert(ZL_CURRENT.auctionlist, fdata.curAuction)
                    index = #ZL_CURRENT.auctionlist
                else
                    ZL_CURRENT.auctionlist[index].startbidamount = fdata.curAuction.startbidamount
                    ZL_CURRENT.auctionlist[index].bidIncrement = fdata.curAuction.bidIncrement
                    ZL_CURRENT.auctionlist[index].state = fdata.curAuction.state
                    ZL_CURRENT.auctionlist[index].countdownremaining = fdata.curAuction.countdownremaining
                    ZL_CURRENT.auctionlist[index].isPaused = fdata.curAuction.isPaused
                    ZL_CURRENT.auctionlist[index].bidderlist = fdata.curAuction.bidderlist
                    ZL_CURRENT.auctionlist[index].itemCount = fdata.curAuction.itemCount
                    ZL_CURRENT.auctionlist[index].isPausedLinshi = fdata.curAuction.isPausedLinshi
                end
                local f = AuctionFrame.entries[index]
                f:SetValues(index)
                if ZL_CURRENT.auctionlist[index].state == "auctioning" and ZL_CURRENT.auctionlist[index]["isPaused"]
                        and ZL_CURRENT.auctionlist[index].isPausedLinshi then
                    ZL_CURRENT.auctionlist[index]["isPaused"] = false
                    ZL_CURRENT.auctionlist[index]["isPausedLinshi"] = false
                    f = AuctionFrame.entries[index]
                    f.Frame1.timer:Resume()
                    f.Frame1.statetext:SetText("拍卖中...")
                    if f.maxAutoBid then
                        f.Frame1.bidbox:Disable()
                        f.Frame1.bidBtn:Disable()
                        f.Frame1.lgnoreBtn:Disable()
                    else
                        f.Frame1.bidbox:Enable()
                        f.Frame1.bidBtn:Enable()
                        f.Frame1.lgnoreBtn:Enable()
                    end
                    f.Frame1.autobidBtn:Enable()
                end
                AuctionFrame:Update()
            elseif fdata.type == "暂停拍卖" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    local f = AuctionFrame.entries[index]
                    f.Frame1.timer:Pause()
                    f.Frame1.statetext:SetText("拍卖暂停中...")
                    f.Frame1.bidbox:Disable()
                    f.Frame1.bidBtn:Disable()
                    f.Frame1.autobidBtn:Disable()
                    ZL_CURRENT.auctionlist[index].isPaused = true
                end
            elseif fdata.type == "继续拍卖" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    ZL_CURRENT.auctionlist[index].isPaused = false
                    local f = AuctionFrame.entries[index]
                    f.Frame1.timer:Resume()
                    f.Frame1.statetext:SetText("拍卖中。。。")
                    if f.maxAutoBid then
                        f.Frame1.bidbox:Disable()
                        f.Frame1.bidBtn:Disable()
                        f.Frame1.lgnoreBtn:Disable()
                    else
                        f.Frame1.bidbox:Enable()
                        f.Frame1.bidBtn:Enable()
                        f.Frame1.lgnoreBtn:Enable()
                    end
                    f.Frame1.autobidBtn:Enable()
                end
            elseif fdata.type == "数量更新" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    ZL_CURRENT.auctionlist[index].itemCount = fdata.itemCount
                    ZL_CURRENT.auctionlist[index].countdownremaining = fdata.countdownremaining
                    local f = AuctionFrame.entries[index]
                    f:SetValues(index)
                end
            elseif fdata.type == "手动倒计时" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    local f = AuctionFrame.entries[index]
                    f.daoShuStart = GetTime()
                    f.Frame1.timer:SetCooldown(GetTime(), fdata.manualCountdownTimer + 1)
                    if f.Frame1.timer:IsPaused() then
                        f.Frame1.timer:Resume()
                        f.Frame1.MLframe.PauseBtn:SetText("暂停")
                        ZL_CURRENT.auctionlist[index].isPaused = false
                    end
                end
            elseif fdata.type == "拍卖成功" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    local f = AuctionFrame.entries[index]
                    f.Frame1.statetext:SetText("拍卖成功！")
                    f.Frame1.bidbox:Disable()
                    f.Frame1.bidBtn:Disable()
                    f.Frame1.autobidBtn:Disable()
                    f.Frame1.autobidBtn:SetText("自动出价")
                    f.maxAutoBid = nil
                    f.Frame1.MLframe.PauseBtn:Disable()
                    f.Frame1.MLframe.PauseBtn:SetText("暂停")
                    f.Frame1.MLframe.CancelBtn:SetText("开始")
                    f.Frame1.MLframe.CancelBtn:Disable()
                    f.Frame1.MLframe.CountDownBtn:Disable()
                    f.Frame1.MLframe.reverseBidBtn:Disable()

                    ZL_CURRENT.auctionlist[index].state = "success"
                    ZL_CURRENT.auctionlist[index].countdownremaining = 0
                    AuctionFrame:Update()

                    --将获胜者数据添加到数据库
                    local bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                    tableSort(bidderlist)
                    for i = 1, math.min(ZL_CURRENT.auctionlist[index].itemCount, #bidderlist) do
                        table.insert(ZL_CURRENT["IncomeList"], {
                            player=bidderlist[i].bidder, amount=bidderlist[i].bidamount, notes=fdata.itemlink
                        })
                        if (not ZL_CURRENT.playerBalance) then ZL_CURRENT.playerBalance = {} end
                        if (not ZL_CURRENT.playerBalance[bidderlist[i].bidder]) then ZL_CURRENT.playerBalance[bidderlist[i].bidder] = {} end
                        --ML自己不需要添加到balance中
                        if (not PlayerIsML(bidderlist[i].bidder)) then
                            ZL_CURRENT.playerBalance[bidderlist[i].bidder]["balance"] =
                                (ZL_CURRENT.playerBalance[bidderlist[i].bidder]["balance"] or 0) - bidderlist[i].bidamount
                        else
                            ZL_CURRENT.playerBalance[bidderlist[i].bidder]["balance"] = 0
                        end
                        ZL_CURRENT.playerBalance[bidderlist[i].bidder]["totalAmount"] =
                            (ZL_CURRENT.playerBalance[bidderlist[i].bidder]["totalAmount"] or 0) + bidderlist[i].bidamount
                        if (not ZL_CURRENT.playerBalance[bidderlist[i].bidder]["items"]) then
                            ZL_CURRENT.playerBalance[bidderlist[i].bidder]["items"] = {}
                        end
                        table.insert(ZL_CURRENT.playerBalance[bidderlist[i].bidder]["items"],{
                            ["notes"] = fdata.itemlink,
                            ["amount"] = bidderlist[i].bidamount,
                            ["isTraded"] = PlayerIsML(bidderlist[i].bidder) and true or false,
                        })
                        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                    end
                end
            elseif fdata.type == "流拍" then
                local data, index = FetchDataFromItemId(fdata.itemId, fdata.itemindex)
                if data then
                    local f = AuctionFrame.entries[index]
                    f.Frame1.statetext:SetText("流拍！")
                    f.Frame1.curbidamounttext:SetText("有效出价：")
                    f.Frame1.curbiddertext:SetText("当前无人出价！")
                    f.Frame1.bidbox:Disable()
                    f.Frame1.bidBtn:Disable()
                    f.Frame1.autobidBtn:Disable()
                    f.Frame1.autobidBtn:SetText("自动出价")
                    f.maxAutoBid = nil
                    f.Frame1.MLframe.PauseBtn:Disable()
                    f.Frame1.MLframe.PauseBtn:SetText("暂停")
                    f.Frame1.MLframe.CancelBtn:SetText("开始")
                    f.Frame1.MLframe.CountDownBtn:Disable()
                    f.Frame1.MLframe.reverseBidBtn:Disable()
                    ZL_CURRENT.auctionlist[index].state = "failed"
                    ZL_CURRENT.auctionlist[index].countdownremaining = 0
                    AuctionFrame:Update()
                end
            elseif fdata.type == "创建拍卖" then
                if (not ZL_CURRENT.auctionlist) then --如果当前不存在拍卖记录，则创建
                    local name, _, difficultyID, _, _, _, _, instanceID = GetInstanceInfo()
                    ZL_CURRENT.auctionlist = {}
                    ZL_CURRENT.name = name
                    ZL_CURRENT.difficultyID = difficultyID
                    ZL_CURRENT.instanceID = instanceID
                    ZL_CURRENT.auctiondate =  date("%Y-%m-%d %H:%M:%S", time())
                    ZL_CURRENT.totalincome = 0
                    ZL_CURRENT.IncomeList = {}
                end
                local data = {
                    ["itemId"] = fdata.itemId,
                    ["itemlink"] = fdata.itemlink,
                    ["itemindex"] = fdata.itemindex,
                    ["startbidamount"] = fdata.startbidamount,
                    ["bidIncrement"] = fdata.bidIncrement,
                    ["state"] = fdata.state,
                    ["lgnore"] = fdata.lgnore,
                    ["countdownremaining"] = fdata.countdownremaining, --可以不用赋值，在启动拍卖的时候已经默认为ZL.opt.auctionTimer
                    ["isPaused"] = fdata.isPaused,
                    ["bidderlist"] = fdata.bidderlist,
                    ["itemCount"] = fdata.itemCount,
                }
                table.insert(ZL_CURRENT.auctionlist, data)
                local index = #ZL_CURRENT.auctionlist
                local f = AuctionFrame.entries[index]
                f:SetValues(index)
                AuctionFrame:Update()
            elseif fdata.type == "添加收支" then
                local player = fdata.player
                local amount = fdata.amount
                local notes = fdata.notes
                if (not ZL_CURRENT.auctionlist) then --如果当前不存在拍卖记录，则创建
                    local name, _, difficultyID, _, _, _, _, instanceID = GetInstanceInfo()
                    ZL_CURRENT.auctionlist = {}
                    ZL_CURRENT.name = name
                    ZL_CURRENT.difficultyID = difficultyID
                    ZL_CURRENT.instanceID = instanceID
                    ZL_CURRENT.auctiondate =  date("%Y-%m-%d %H:%M:%S", time())
                    ZL_CURRENT.totalincome = 0
                    ZL_CURRENT.IncomeList = {}
                end
                table.insert(ZL_CURRENT.IncomeList, {
                    player = player,
                    amount = amount,
                    notes = notes,
                })
                if string.len(player) > 0 then
                    if (not ZL_CURRENT.playerBalance) then ZL_CURRENT.playerBalance = {} end
                    ZL_CURRENT.playerBalance[player]["balance"] = (ZL_CURRENT.playerBalance[player]["balance"] or 0) - amount
                    ZL_CURRENT.playerBalance[player]["totalAmount"] = (ZL_CURRENT.playerBalance[player]["totalAmount"] or 0) + amount
                    if (not ZL_CURRENT.playerBalance[player]["items"]) then
                        ZL_CURRENT.playerBalance[player]["items"] = {}
                    end
                    table.insert(ZL_CURRENT.playerBalance[bidderlist[i].bidder]["items"],{
                        ["notes"] = notes,
                        ["amount"] = amount,
                        ["isTraded"] = false,
                    })
                    ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                end
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            elseif fdata.type == "删除拍卖记录" then
                local v = fdata.index
                local playerName = ZL_CURRENT["IncomeList"][v]["player"]
                local amount = ZL_CURRENT["IncomeList"][v]["amount"]
                local notes = ZL_CURRENT["IncomeList"][v]["notes"]
                if strlen(playerName) > 0 then
                    ZL_CURRENT["playerBalance"][playerName]["balance"] = ZL_CURRENT["playerBalance"][playerName]["balance"] + amount
                    ZL_CURRENT["playerBalance"][playerName]["totalAmount"] = ZL_CURRENT["playerBalance"][playerName]["totalAmount"] + amount
                    if ZL_CURRENT["playerBalance"][playerName]["items"] then
                        for index, data in ipairs(ZL_CURRENT["playerBalance"][playerName]["items"]) do
                            if (data.notes == notes) and (data.amount) == amount and (not data.isTraded) then
                                table.remove(ZL_CURRENT["playerBalance"][playerName]["items"], index)
                                break
                            end
                        end
                    end
                    ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                end
                table.remove(ZL_CURRENT["IncomeList"], v)
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
            elseif fdata.type == "" then
            end
        end
    elseif (prefix == "AUTOAUC RESET") then
        if (not PlayerIsML()) and (PlayerIsML(sender)) then
            if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                    local f = AuctionFrame.entries[num]
                    if data.state == "auctioning" then
                        f.Frame1.timer.updateframe:Hide()
                        f.Frame1.statetext:SetText("拍卖已取消，等待重新拍卖")
                        f.Frame1.curbidamounttext:SetText("有效出价：")
                        f.Frame1.curbiddertext:SetText("当前无人出价！")
                        if f.Frame1.timer:IsPaused() then
                            f.Frame1.timer:Resume()
                            f.Frame1.MLframe.PauseBtn:SetText("暂停")
                        end
                        f.Frame1.timer:SetCooldown(0, 0)
                        f.Frame1.bidbox:Disable()
                        f.Frame1.bidBtn:Disable()
                        f.Frame1.autobidBtn:Disable()
                        f.Frame1.MLframe.PauseBtn:Disable()
                        f.Frame1.MLframe.CountDownBtn:Disable()
                        f.Frame1.MLframe.reverseBidBtn:Disable()
                    end
                    f:Hide()
                end
                local totalincome = 0
                if ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                    for _, data in ipairs(ZL_CURRENT.IncomeList) do
                        totalincome = totalincome + data.amount
                    end
                end
                ZL_CURRENT.totalincome = totalincome
                -- ZL_CURRENT.name = ZL_CURRENT.auctiondate
                table.insert(ZL_HISTORY, ZL_CURRENT)
                ZL_CURRENT = {OpenLootList={}, GroupMembersVersion={}}
                AuctionFrame:Update()
                ZL.AuctionRecordFrame.historyFrame:Update()
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
        end
    elseif (prefix == "AUTOAUC PRO") then
        if (not PlayerIsML()) and (PlayerIsML(sender)) then 
            ZL.opt.auctionTimerRefresh = fdata.auctionTimerRefresh
            ZL.opt.auctionTimer = fdata.auctionTimer
        end
    elseif (prefix == "AUTOAUC REVOKE") then
        if (PlayerIsML(sender)) then
            local itemId = fdata.itemId
            local itemindex = fdata.itemindex
            local sdata, index = FetchDataFromItemId(itemId, itemindex)
            if sdata then
                local playerName = fdata.playerName
                local bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                if bidderlist and #bidderlist then
                    for num, data in ipairs(bidderlist) do
                        if data.bidder == playerName then
                            table.remove(ZL_CURRENT.auctionlist[index].bidderlist, num)
                            tableSort(ZL_CURRENT.auctionlist[index].bidderlist)
                            bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                            local f = AuctionFrame.entries[index]
                            ZL_CURRENT.auctionlist[index].countdownremaining = ZL.opt.auctionTimerRefresh--更新了出价，重新倒计时
                            f:SetValues(index)
                            if PlayerIsML() then
                                local msgStr = ""
                                local newBid = 0
                                local curAuctionList = ZL_CURRENT.auctionlist[index]
                                bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                                if bidderlist[curAuctionList.itemCount] then
                                    newBid = bidderlist[curAuctionList.itemCount].bidamount + curAuctionList.bidIncrement
                                else
                                    newBid = curAuctionList.startbidamount
                                end
                                if #bidderlist > 0 then
                                    for i = 1, math.min(curAuctionList.itemCount, #bidderlist) do
                                        msgStr = msgStr .. bidderlist[i].bidamount .. "g，"
                                    end
                                    msgStr = ("[%d]%s已撤销%s的出价，有效出价：%s下次最低出价：%dg"):format(
                                        curAuctionList.itemindex, curAuctionList.itemlink, playerName, msgStr, newBid
                                    )
                                    SendChatMessage(msgStr, "RAID")
                                else
                                    SendChatMessage(("[%d]%s已撤销%s的出价，当前无人出价，起步价：%dg，每次最低加价：%dg"):format(
                                        index, curAuctionList.itemlink, playerName, curAuctionList.startbidamount,
                                        curAuctionList.bidIncrement), "RAID")
                                end
                            end
                            break
                        end
                    end
                end
            end
        end
    elseif (prefix == "AUTOAUC VER") then
        if fdata.type == "request" then
            if (not PlayerIsML()) and (PlayerIsML(sender)) then
                local data = {type="requestback", ver=ZL.addonVersion}
                MyAddon:TransmitAddonInfo2("AUTOAUC VER", data, "WHISPER", sender)
            end
        elseif fdata.type == "requestback" then
            if PlayerIsML() then
                -- print(Prefix(sender .. " 版本号：" .. fdata.ver))
                ZL_CURRENT.GroupMembersVersion[sender] = fdata.ver
            end
        end
    else

    end
end

